import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/dist/vite'
import Components from 'unplugin-vue-components/dist/vite'
import postcssNesting from "postcss-nesting"
import { resolve } from "path";
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig({
  base: "./",// 打包时打包位置，不按照这个会找不到项目关联文件位置
  plugins: [
    vue(),
    // 自动引入配置
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'src/auto-import.d.ts'
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      dts: 'src/components.d.ts'
    })
  ],
  // 配置scss，样式
  css: {
    postcss: {
      plugins: [
        postcssNesting
      ]
    }
  },
  server: {
    proxy: {
      // 后端配置地址
      '/back': {
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/back/, '')
      }
    }
  },
  // 配置@别名，在引入文件的时候可以用@代替到
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
      "@types": resolve(__dirname, "./src/types")
    }
  }
})
